// Copyright 2006 Bret Taylor
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

#ifndef INDIE_LOG_H__
#define INDIE_LOG_H__

#include <string>

#include "filelocation.h"

using std::string;

namespace indie {

class Log {
  public:
    Log(bool report_warnings = true, bool report_errors = true);
    virtual ~Log();

    void Error(const FileLocation& location, const char* format, ...);
    void Warning(const FileLocation& location, const char* format, ...);

    inline int num_warnings() const {
	return num_warnings_;
    }

    inline int num_errors() const {
	return num_errors_;
    }

    inline void reset() {
	num_warnings_ = 0;
	num_errors_ = 0;
    }

    inline bool report_warnings() const {
	return report_warnings_;
    }

    inline bool report_errors() const {
	return report_errors_;
    }

    inline bool has_errors() const {
	return num_errors() > 0;
    }

    inline void set_report_warnings(bool report_warnings) {
	report_warnings_ = report_warnings;
    }

    inline void set_report_errors(bool report_errors) {
	report_errors_ = report_errors;
    }

  protected:
    virtual void HandleError(const FileLocation& location,
			     const string& message);
    virtual void HandleWarning(const FileLocation& location,
			       const string& message);

  private:
    bool report_warnings_;
    bool report_errors_;
    int num_warnings_;
    int num_errors_;

    static const unsigned int kBufferSize;
};

}

#endif  // INDIE_LOG_H__
